/*
 * @Author: ckk
 * @Date: 2022-10-20 14:34:04
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2023-08-30 14:17:26
 * @Description: 用户信息
 */
import axios from './request';
import yaxios from 'axios';
/**
 * @description: Token获取用户信息
 * @param {*}
 * @Author: ckk
 * @Date: 2022-10-21 11:13:29
 * @return {*}
 */
export async function getUserInfo () {
  const { data } = await axios.get('/gw/ucsapi/sch/student/v1/stuinfo');
  return data;
}
/**
 * @description: 家长信息-主要查询手机号
 * @param {*}
 * @Author: ltl
 * @Date: 2023-8-29 11:06:46
 * @return {*}
 */
export async function getParentInfo () {
  const { data } = await axios.get('/gw/ucsapi/sso/api/getTokenInfo');
  return data;
}
/**
 * @description: 获取切换孩子列表信息
 * @param {*}
 * @Author: ltl
 * @Date: 2023-8-29 15:51:32
 * @return {*}
 */
export async function getChildList () {
  const { data } = await axios.get('/gw/ucsapi/sso/auth/token/parent_app/users');
  return data;
}
/**
 * @description: 切换角色账号
 * @param {*}
 * @Author: ltl
 * @Date: 2023-8-29 16:23:05
 * @return {*}
 */
export async function switchAccountNumber (params) {
  const { data } = await yaxios({
    method: 'POST',
    url: '/gw/ucsapi/sso/oauth/token?grant_type=role_change',
    headers: {
    Authorization: 'Basic ' + 'dXhpbjowNjNiMzdiYjIzNTY1MzdiMjMxNTQ1NGYxYjc4ODhkOQ==',
    'content-type': 'application/x-www-form-urlencoded'
    },
    params: params
  }
);
  return data;
}
/**
 * @description: 获取学生今日签到状态
 * @param {*}
 * @Author: ckk
 * @Date: 2022-10-21 16:53:36
 * @return {*}
 */
export async function getSignStatus () {
  const { data } = await axios.get('/ub/interface/is_sign.jsp');
  return data;
}
/**
 * @description: 签到
 * @param {*} params
 * @Author: ckk
 * @Date: 2022-10-21 16:57:43
 * @return {*}
 */
export async function SignIn (params) {
  const { data } = await axios.post(`${process.env.VUE_APP_NRMS_URL}/rms/v1/clocktask/commit_task`, { ...params });
  return data;
}
/**
 * @description: 上报签到
 * @param {*} params
 * @Author: ckk
 * @Date: 2022-10-27 17:41:17
 * @return {*}
 */
export async function getReport (params) {
  const Qs = require('qs'),
   { data } = await axios({
    method: 'POST',
    url: '/ub/interface/data_report.jsp',
    headers: {
      'content-type': 'application/x-www-form-urlencoded'
    },
    data: Qs.stringify(params)

  }
  );
  return (data || {});
}
export async function getHeadPhoto (userName, size) {
  try {
    const { data } = await axios.get(`${process.env.VUE_APP_UC_URL}/head_photo/user/${userName}/${size}`,
      {
        responseType: 'arraybuffer'
      });
    return 'data:image/png;base64,' + btoa(
      new Uint8Array(data)
        .reduce((data, byte) => data + String.fromCharCode(byte), '')
    );
  } catch (error) {
  }
}
// 设置年级
export async function setGrade (params) {
  const { data } = await axios.post(`${process.env.VUE_APP_UC_URL}/isch-c/v1/user/stage/grade/choice`, { ...params });
  return data;
}
export async function getGrade (params) {
  const { data } = await axios.get(`${process.env.VUE_APP_UC_URL}/isch-c/v1/edu-years/stage/grade`,
  { params });
  return data;
}
